***********replication analytic code for estimating effects of paid maternity on neonatal mortality***************;
********results provided in "Increased duration of paid maternity leave lowers infant mortality in low- and middle-
income countries: a quasi-experimental study" by Nandi et al., published in PLOS MEDICINE on March 29, 2016*******;


*IMPORT DATASET FOR ANALYSIS OF NEONATAL MORTALITY, NAMED 'NEOM_rep_20160601';

libname rep 'X:\'; *insert directory where replication file 'NEOM_rep_20160601' is stored;
run;

data neom_rep;
set rep.NEOM_rep_20160601;
run;

proc contents data=neom_rep varnum short; run;

proc sort data=neom_rep; by iso3 yearbirth; run;


*WE CONDUCTED A COMPLETE CASE ANALYSIS THAT RESTRICTED ANALYSES TO OBSERVATIONS WITH NONMISSING COVARIATE VALUES;

data neom_rep; 
set neom_rep;
if ftem>. and durm>. and neodeath>. and male>. and edumother>. and wq2-wq5>. and urban>. 
and bthinval24>. and age2039>. and age40>. and brdelpro>.; 
run;


*MAIN ANALYSES (Table 4). The following models correspond to models (1)-(3) in table 3: Effects of an increase in paid 
maternity leave, measured by an additional month of paid leave, on the number of neonatal deaths per 1000 live births, 
Demographic and Health Surveys, 2001-2008;

*model 1: with fixed effects for country and year;

proc surveyreg data=neom_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model neodeath=durm_lag1 iso3 yearbirth/solution clparm;
weight dnwt;
run;


*Model 2: Model 1 + measured individual, household, and country-level characteristics;

proc surveyreg data=neom_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model neodeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp /solution clparm;
weight dnwt;
run;


*Model 3: Model 2 + per capita total and government health expenditures--these data were unavailable for all 
years for Zimbabwe and observations from Zimbabwe were therefore dropped from Model 3;

proc surveyreg data=neom_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model neodeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
run;


*ANCILLARY ANALYSES;

*Table S2. effect of effect of paid maternity leave on neonatal morality on the risk ratio scale;

proc genmod data=neom_rep descending order=freq;
class iso3 yearbirth;
model neodeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/link=log dist=poisson;
repeated subject=iso3/type=ind; 
weight dnwt;
run;


*Table S3 and Figure S2. Models examining potential non-linearity in the effect of paid maternity leave on neonatal morality 
by introducing a quadratic duration of paid leave variable to a fully adjusted model;

proc surveyreg data=neom_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model neodeath=durm_lag1|durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
store nonlin_neo;
run;

ods graphics on;
proc plm source=nonlin_neo;
effectplot fit (x=durm_lag1);
run;
ods graphics off;


*SENSITIVITY ANALYSES (Table S5). the following models correspond to models (a)-(d) in table S5:

*Model a. measures the effects of an additional month of paid leave in full time equivalent (FTE) units, 
obtained by multiplying the legislated length of leave by the wage replacement rate (therefore this model does 
not additionally control for the wage replacement rate);

proc surveyreg data=neom_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model neodeath=ftem_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
run;


*Model b. unweighted estimates;

proc surveyreg data=neom_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model neodeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
run;


*Model c. this model added to our primary exposure, the lagged effect of paid maternity leave (t-1), 
parameters representing paid maternity leave in preceding years (t-3, t-2), the survey year (t), 
and subsequent years (t+1, t+2, t+3); 

proc surveyreg data=neom_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model neodeath=durm_lag3 durm_lag2 durm_lag1 durm durm_lead1 durm_lead2 durm_lead3 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
run;


*Model d. this model restricted the set of control countries to those with similar trends in neonatal mortality 
in the decade prior to the study period, as described in the S2 Text;

data neom_rep_matched; 
set neom_rep;
if iso3 in ('ZWE', 'BGD', 'KEN', 'LSO', 'UGA', 'ARM', 'BOL', 'EGY', 'HND', 'MDG', 'MWI', 'NPL', 'TZA');
run;


proc surveyreg data=neom_rep_matched order=freq;
cluster iso3;
class iso3 yearbirth;
model neodeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
run;

